<template>
	<view class="lists">
		<view style="width: 100%;height: 20upx;background: #ECECEC;"></view>
		<view class="location">
			<view class="location_nav" v-for="(item,index) in location" :kye='index'>
				<view class="location_text" @longtap="deletes(item.id)">
					<view class="location_text1"><text>{{item.consignee}}</text>{{item.phone}}</view>
					<view style="font-size: 30upx;color: #CACACA;" class="location_text2">
						<text v-if="item.defaultAddress>=1" class="default">
						<text>默认</text>
						</text>
						<text>{{item.province}}   {{item.city}}   {{item.county}}</text>{{item.address}}
					</view>
				</view>
				<view class="location_img" @click="address(item.id)">
					<image src="../../static/修改地址.png" mode=""></image>
				</view>
			</view>
		</view>
		<view class="confirm-btns" @click="create()">
			<text> 新增地址 </text>
		</view> 
	</view>
	</view>
</template>

<script>
	import uniPopupDelete from '@/components/uni-popup/uni-popup-delete.vue'
	export default {
		data(){
			return{
				location:[],
				Token:"",
				id:""
			}
		},
		methods:{
			deletes(e){
				var _this=this;
				console.log(e)
				uni.showModal({
				         title: '删除提示',
				         content: '你确定删除地址吗？',
				         success: function (res) {
				             if (res.confirm) {
								uni.request({
									url:_this.$C.webUrl+`m.api?_gp=address&_mt=deleteAddress&addressId=${e}`,
									header: {
										accessToken: this.Token
									},
									success: (res) => {
										 console.log(res)
									}
								})
				             } else if (res.cancel) {
				                 console.log('用户点击取消');
				             }
				         }
				     });
			},
			close(done){
			            done()
			        },
			        confirm(done,value){
			            // 输入框的值
			            console.log(value)
			            // TODO 做一些其他的事情，手动执行 done 才会关闭对话框
			            // ...
			            done()
			        },
			open(){
			         this.$refs.popup.open()
			      },
			address(e){
				uni.navigateTo({
					url:'../create/address?id='+e
				})
			},
			create(){
				uni.navigateTo({
					url:'../create/index'
				})
			}
		},
		onLoad() {
			console.log(this.compile,this.GLOBAL)
			this.Token = uni.getStorageSync('Token')
			uni.request({
				url:this.$C.webUrl+'m.api?_gp=address&_mt=getAllAddress',
				header:{
					'accessToken':this.Token
				},
				success: (res) => {
					console.log(res)
					 this.location=res.data.data
				}
			})
		}
	}
</script>

<style>
	.lists{
		width: 100%;
		height: 80%;
	}
	.default text{
		font-size: 12px;
		    color: #fa436a;
			padding-right: 5px !important;
	}
	>>>.default{
		padding-right: 0px !important;
		font-size: 12px;
		    color: #fa436a;
		    margin-right: 5px;
		    background: #fffafb;
		    border: 1px solid #ffb4c7;
		    border-radius: 2px;
		    padding: 2px 5px;
		    line-height: 1;
		}

	.location{
		width: 100%;
		margin-bottom: 50upx;
	}
	.location_nav{
		width: 90%;
		display: flex;
		justify-content: space-between;
		margin:30upx auto;
		border-bottom: 1px solid #CCCCCC;
	}
	.location_text1{
		font-size: 30upx;
	}
	.location_text1 text{
		padding-right: 30upx;
	}
	.location_text2{
		padding: 10upx 0px;
	}
	.location_text2 text{
		padding-right: 30upx;
	}
	.location_img image{
		width: 50upx;
		height: 50upx;
	}
	.confirm-btns{
		     width: 320px;
		    height: 38px;
		    line-height: 38px;
		    border-radius: 50px;
		    margin-top: 35px;
		    background: #fa436a;
		    color: #fff;
		    font-size: 16px;
			text-align: center;
			display: flex;
			justify-content: center;
		    position: fixed;
			bottom: 40upx;
			left: 50upx;
	}
</style>
